package fl.ass.service.api;

import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.IPriorityApiService;
import cmm.user.facade.system.dto.SysUsrDatAuthRDTO;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import fl.ass.facade.api.IAssDealCarApi;
import fl.ass.facade.api.IAssFileLogApi;
import fl.ass.facade.condition.AssDealCarQueryCondition;
import fl.ass.facade.condition.AssFileLogQC;
import fl.ass.facade.dto.AssDealCarCostDTO;
import fl.ass.facade.dto.AssDealCarDTO;
import fl.ass.facade.dto.AssFileLogDTO;
import fl.ass.facade.dto.MessageDTO;
import fl.ass.service.service.IAssDealCarCostService;
import fl.ass.service.service.IAssDealCarService;
import fl.ass.service.service.IAssFileLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 处置转优车API
 *
 * @author zy
 */
@Component
public class AssFileLogApi implements IAssFileLogApi {

    private static final Logger logger = LoggerFactory.getLogger(AssFileLogApi.class);

    @Autowired
    private IAssFileLogService assFileLogService;

    /*
     * 保存(处置-转优车资料信息表)
     */
    @Override
    public MessageDTO<String> saveAssFileLog(AssFileLogDTO dto) {
        MessageDTO<String> response = new MessageDTO<String>();
        if (null == dto) {
            response.setMessage("parameter：dto is can not be null");
        }
        try {
            Long id = assFileLogService.add(dto);
            response.setId(id);
            response.setSuccess(true);
        } catch (Exception e) {
            BaseLogUtils.newLogger("异常!" + e.getMessage()).setThrowable(e).info();
            response.setMessage(e.getMessage());
        }
        return response;
    }

    /**
     * 不分页查询转优车资料信息
     *
     * @param qc
     * @return
     * @throws BaseException
     */
    @Override
    public MessageDTO<AssFileLogDTO> selectList(
            AssFileLogQC qc) throws BaseException {
        MessageDTO<AssFileLogDTO> response = new MessageDTO<AssFileLogDTO>();
        if (null == qc.getOptId() && null == qc.getOptId()) {
            response.setMessage("parameter：optimalId is can not be null");
        }
        try {
            List<AssFileLogDTO> dtos = assFileLogService.searchList(qc);
            if (null != dtos) {
                response.setDatas(dtos);
            }
            response.setSuccess(true);
        } catch (Exception e) {
            BaseLogUtils.newLogger("异常!" + e.getMessage()).setThrowable(e).info();
            response.setMessage(e.getMessage());
        }
        return response;
    }

    /**
     * 根据主键获取转优车维护资料信息
     * @param id
     * @return
     */
    @Override
    public MessageDTO<AssFileLogDTO> findAssFileLogById(Long id) {
        MessageDTO<AssFileLogDTO> response = new MessageDTO<AssFileLogDTO>();
        if(null == id){
            response.setMessage("parameter：id is can not be null");
        }
        try {
            AssFileLogDTO dto = assFileLogService.selectById(id);
            if(null != dto){
                response.setData(dto);
            }
            response.setSuccess(true);
        } catch (Exception e) {
            BaseLogUtils.newLogger("异常!" + e.getMessage()).setThrowable(e).info();
            response.setMessage(e.getMessage());
        }
        return response;
    }

    /**
     * 修改(处置-转优车资料信息表)
     * @param dto
     * @return
     */
    @Override
    public MessageDTO<String> modifyAssFileLogCost(AssFileLogDTO dto) throws BaseException {
        MessageDTO<String> response = new MessageDTO<String>();
        if(null == dto){
            response.setMessage("parameter：dto is can not be null");
        }
        try {
            this.assFileLogService.modify(dto);
            response.setSuccess(true);
        } catch (Exception e) {
            BaseLogUtils.newLogger("异常!" + e.getMessage()).setThrowable(e).info();
            response.setMessage(e.getMessage());
        }
        return response;
    }
}
